/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tools;

import com.aptech.bluepumpkin.Registration;
import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import javax.faces.model.ListDataModel;
import org.primefaces.model.SelectableDataModel;

/**
 *
 * @author Trong Nguyen
 */
public final class RegistrationDataModel extends ListDataModel<Registration> implements SelectableDataModel<Registration>, Serializable {

    public RegistrationDataModel() {
    }

    public RegistrationDataModel(List<Registration> list) {
        super(list);
        List<Registration> lists = (List<Registration>) getWrappedData();
        buildHashMap(lists);

    }
    private HashMap<Integer, Registration> maps = new HashMap<Integer, Registration>();

    public void buildHashMap(List<Registration> list) {
        maps.clear();
        if (null == list || list.isEmpty()) {
            return;
        }

        for (Registration registration : list) {
            maps.put(registration.getId(), registration);

        }
    }

    @Override
    public Object getRowKey(Registration object) {
        if (null != object) {
            return object.getId();
        } else {
            return null;
        }
    }

    @Override
    public Registration getRowData(String rowKey) {
        Integer id = new Integer(rowKey);
        return maps.get(id);
    }
}
